import time

from selenium.webdriver.common.by import By

from common.Utils import BlogDriver

class BlogLoginTest:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:9580/sign-in.html"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)

    #元素检测
    def LoginEleTest(self):
        #用户名&密码输入框是否可以输入
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")

        #“眼睛”显示填入信息按钮是否可以点击显示信息
        self.driver.find_element(By.CSS_SELECTOR,"#password_a > svg").click()
        BlogDriver.getScreeShot()

        #登录按钮是否可以点击
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        BlogDriver.getScreeShot()

        self.driver.refresh()

        #注册选项是否可以点击跳转
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page.page-center > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()
        self.driver.find_element(By.CSS_SELECTOR,"#submit")
        BlogDriver.getScreeShot()
        self.driver.back()

    # 异常登录
    def LoginFailTest(self):
        # 正确用户名&错误密码
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("2890556976")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123000")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        BlogDriver.getScreeShot()
        self.driver.refresh()

        # 错误用户名&正确密码
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("2890557669")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123321")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        BlogDriver.getScreeShot()
        self.driver.refresh()

        # 错误用户名&错误密码
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("2890557669")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123111")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        BlogDriver.getScreeShot()
        self.driver.refresh()

    #正常登录
    def LoginSucTest(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("2890556976")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123321")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()

        #找到则登录成功
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar")
        BlogDriver.getScreeShot()





